import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import AutoImport from 'unplugin-auto-import/vite'
import path from "path";
import { UnifiedViteWeappTailwindcssPlugin as uvwt } from "weapp-tailwindcss/vite";
// https://vitejs.dev/config/

const isH5 = process.env.UNI_PLATFORM === "h5";
const isApp = process.env.UNI_PLATFORM === "app";
const WeappTailwindcssDisabled = isH5 || isApp;
const resolve = (p : string) => {
	return path.resolve(__dirname, p);
};

export default defineConfig({
	plugins: [uni(),
	AutoImport({
		imports: ['vue', 'pinia', 'uni-app'],
		dts: 'src/auto-import.d.ts',
	}),
	uvwt({
		rem2rpx: true,
		disabled: WeappTailwindcssDisabled,
		// 由于 hbuilderx 会改变 process.cwd 所以这里必须传入当前目录的绝对路径
		tailwindcssBasedir: __dirname
	})
	],
	// start 引入tailwindcss增加的配置postcss
	css: {
		postcss: {
			plugins: [
				require("tailwindcss")({
					// 注意此处，手动传入你 `tailwind.config.js` 的绝对路径
					config: resolve("./tailwind.config.js")
				}),
				require("autoprefixer")
			],
		},
	},
	// end 引入tailwindcss增加的配置postcss
	server: {
		port: 8080,
		host: '0.0.0.0',
		open: true,
		cors: true,
	},
	build: {
		minify: 'terser',
		terserOptions: {
			compress: {
				drop_console: true,
			},
		},
	},
});